import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:getwidget/components/search_bar/gf_search_bar.dart';

import '../controllers/gfsearchbar_controller.dart';

class GfsearchbarView extends GetView<GfsearchbarController> {
  List list = [
    "Flutter",
    "React",
    "Ionic",
    "Xamarin",
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('搜索框'),
        centerTitle: true,
      ),
      body: Container(
        child: ListView(
          children: [
            GFSearchBar(
              searchList: list,
              searchQueryBuilder: (query, list) {
                return list.where((item) =>
                  item!.toString().toLowerCase().contains(query.toLowerCase()))
                  .toList();
              },
              overlaySearchListItemBuilder: (item) {
                return Container(
                  padding: const EdgeInsets.all(8),
                  child: Text(
                    item.toString(),
                    style: const TextStyle(fontSize: 18),
                  ),
                );
              },
              onItemSelected: (item) {
                print('$item');
              },
            ),
          ],
        ),
      ),
    );
  }
}
